package com.example.demo.controller;

import com.example.demo.model.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping("/students")
    public List<Student> getStudents() {return studentService.list();}

    @GetMapping("/student/{id}")
    public Student getStudent(@PathVariable int id) {return studentService.getById(id);}

    @PostMapping("/student")
    public void addStudent(@RequestBody Student student) {studentService.save(student);}

    @PutMapping("/student")
    public void updateStudent(@RequestBody Student student) {studentService.updateById(student);}

    @DeleteMapping("/student/{id}")
    public void deleteStudent(@PathVariable int id) {studentService.removeById(id);}
}
